﻿using System;
using System.IO.IsolatedStorage;

namespace CoreSharp.ThaiSMS
{
    public class ApplicationSettings
    {

		#region Singleton Pattern
			
		private static ApplicationSettings _Default;

		private ApplicationSettings()
		{
		}

		///<summary>
		/// Get the default instance of ApplicationSettings
		///</summary>
		public static ApplicationSettings Default
		{
			get
			{
				if ( _Default == null )
				{
					_Default = new ApplicationSettings();
				}
				return _Default;
			}
		}
		
		#endregion

        public object this[string key]
        {
            get
            {
                if (IsolatedStorageSettings.ApplicationSettings.Contains(key))
                    return IsolatedStorageSettings.ApplicationSettings[key];

                return null;
            }
            set
            {
                if (IsolatedStorageSettings.ApplicationSettings.Contains(key))
                {
                    IsolatedStorageSettings.ApplicationSettings[key] = value;
                }
                else
                {
                    IsolatedStorageSettings.ApplicationSettings.Add(key, value);
                }
            }
        }

        public void Save()
        {
            IsolatedStorageSettings.ApplicationSettings.Save();
        }
    }
}
